﻿Imports BUS, DTO
Public Class frmtiepnhansach

    Private Sub frmtiepnhansach_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim loaisachBUS As New LoaiSachBUS()
        Dim tacgiaBUS As New TacGiaBUS()
        Dim nsxBUS As New NhaXuatBanBUS()
        Dim nhanvienBUS As New NhanVienBUS()
        Dim tinhtrangsachBUS As New TinhTrangBUS()


        Dim dsLS As New List(Of LoaiSachDTO)
        Dim dsTG As New List(Of TacGiaDTO)
        Dim dsNXB As New List(Of NhaXuatBanDTO)
        Dim dsNV As New List(Of NhanVienDTO)
        Dim dsTTS As New List(Of TinhTrangDTO)

        dsLS = loaisachBUS.LayDSLoaiSach()
        dsTG = tacgiaBUS.LayDSTacGia()
        dsNXB = nsxBUS.LayDSNhaSanXuat()
        dsNV = nhanvienBUS.LayDSNhanVien_ThuKho()
        dsTTS = tinhtrangsachBUS.LayDSTinhTrang()

        LookUptheloai.Properties.DataSource = dsLS
        LookUptheloai.Properties.ValueMember = "MaTheLoai"
        LookUptheloai.Properties.DisplayMember = "TenTheLoai"

        LookUpEdit_TacGia.Properties.DataSource = dsTG
        LookUpEdit_TacGia.Properties.ValueMember = "MaTacGia"
        LookUpEdit_TacGia.Properties.DisplayMember = "TenTacGia"

        LookUpEdit_NhaXuatBan.Properties.DataSource = dsNXB
        LookUpEdit_NhaXuatBan.Properties.ValueMember = "MaNhaSanXuat"
        LookUpEdit_NhaXuatBan.Properties.DisplayMember = "TenNhaSanXuat"

        LookUpnguoitiepnhan.Properties.DataSource = dsNV
        LookUpnguoitiepnhan.Properties.ValueMember = "MaNhanVien"
        LookUpnguoitiepnhan.Properties.DisplayMember = "HoTen"

        LookUpEdit_TinhTrangSach.Properties.DataSource = dsTTS
        LookUpEdit_TinhTrangSach.Properties.ValueMember = "MaTinhTrangSach"
        LookUpEdit_TinhTrangSach.Properties.DisplayMember = "TenTinhTrangSach"

        LookUpEdit_NhaXuatBan.EditValue = 0
        LookUpEdit_TacGia.EditValue = 0
        LookUpnguoitiepnhan.EditValue = 0
        LookUptheloai.EditValue = 0
        LookUpEdit_TinhTrangSach.EditValue = 0

        DateEditngaynhap.DateTime = DateTime.Now


    End Sub

    Private Sub btntiepnhan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntiepnhan.Click
        Dim str As String = String.Format("{0:dd/MM/yyyy}", DateEditngaynhap.DateTime)
        Dim sql As String = "insert into SACH (TenSach,MaTheLoai,MaTacGia,NamXuatBan,MaNhaSanXuat,NgayNhap,TriGia,MaNhanVien,MaTinhTrangSach) "
        sql += "Values('" + txttensach.Text + "'," + LookUptheloai.EditValue.ToString() + ", " + LookUpEdit_TacGia.EditValue.ToString() + ", " + SpinEdit_NamXuatBan.Value.ToString()
        sql += " , " + LookUpEdit_NhaXuatBan.EditValue.ToString() + ",'" + str + "', " + SpinEdit_TriGia.Value.ToString() + "," + LookUpnguoitiepnhan.EditValue.ToString() + ", " + LookUpEdit_TinhTrangSach.EditValue.ToString() + ")"

        Dim bus As New SachBUS()
        Dim kq As Integer = bus.ThemSach(sql)

        If kq = 1 Then
            MessageBox.Show("Thêm sách thành công !")
        Else
            MessageBox.Show("Thêm sách thất bại!")
        End If
        Me.Close()

    End Sub
End Class